package com.xsmart.goods.dao.wx;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public interface WxIndexDataDao {

    /**
     * 查询首页推荐
     * @param priorityMap
     * @return
     */
    @Select("<script>" +
            "SELECT a.priority_id,c.detail_url,b.seat_name,d.obj_title,d.obj_img,aa.goods_name,aa.is_promote," +
            "DATE_FORMAT(aa.promote_start_date,'%Y-%m-%d %T') promote_start_date," +
            "DATE_FORMAT(aa.promote_end_date,'%Y-%m-%d %T') promote_end_date, " +
            "aa.promote_price,a.obj_id, aa.is_on_sale, " +
            "<choose> " +
            "<when test='sellerId!=-1'>(select shop_price from user_seller_goods tt where tt.goods_id = aa.goods_id and tt.id = #{sellerId}) goods_price </when>" +
            "<when test='sellerId==-1'>aa.shop_price goods_price </when>" +
            "</choose>" +
//            "(select shop_price from user_seller_goods tt where tt.goods_id = aa.goods_id and tt.id = #{sellerId}) goods_price " +
//            "<![CDATA[(case when aa.is_promote=1 and aa.promote_start_date <= NOW() and aa.promote_end_date >= NOW() then aa.promote_price ELSE aa.shop_price END)]]>  goods_price  " +
            "FROM yy_priority a " +
            "left JOIN yy_seat b ON b.seat_id = a.seat_id " +
            "LEFT JOIN yy_detail_url c ON c.du_id = a.du_id " +
            "LEFT JOIN yy_priority_info d ON d.priority_id=a.priority_id " +
            "LEFT JOIN goods aa on a.obj_id = aa.goods_id " +
            "where b.seat_code = #{seatCode} " +
            "and b.seat_type = #{seatType} " +
            "and a.status= 1 " +
            "and aa.is_on_sale != 0" +
            "<![CDATA[ and a.start_time <= NOW() " +
            "and a.end_time >= NOW() ]]>" +
            "<if test=\"sellerId!=-1\">and aa.goods_id in (select goods_id  from user_seller_goods t where t.id =#{sellerId})</if> " +
            "</script>")
    List<Map<String,Object>> queryIndex(Map<String, Object> priorityMap);

    /**
     * 查询首页分类推荐
     * @param priorityMap
     * @return
     */
    @Select("<script>" +
            "SELECT a.priority_id,c.detail_url,b.seat_name,d.obj_title,d.obj_img,a.obj_id " +
            "FROM yy_priority a " +
            "left JOIN yy_seat b ON b.seat_id = a.seat_id " +
            "LEFT JOIN yy_detail_url c ON c.du_id = a.du_id  " +
            "LEFT JOIN yy_priority_info d ON d.priority_id=a.priority_id  " +
            "LEFT JOIN category e ON e.cat_id = a.obj_id " +
            "where b.seat_code =  #{seatCode} " +
            "and b.seat_type = #{seatType} and a.status= 1 " +
            "<![CDATA[ and a.start_time <= NOW()  " +
            "and a.end_time >= NOW() ]]> " +
            "</script>")
    List<Map<String,Object>> queryCategoryPriority(Map<String, Object> priorityMap);


    /**
     * 查询首页推荐商品
     * @return
     */
    @Select("select brand_logo photo from brand limit 0,20")
    List<Map<String,Object>> queryIndexBrand();
}
